package org.example.examfx02;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.io.IOException;

public class HelloApplication extends Application {
    public static Stage addView(String url,int x,int y,String title){
        Stage stage = new Stage();
        Parent root = null;
        try{
            root = FXMLLoader.load(HelloApplication.class.getResource(url));
            Scene scene = new Scene(root);
            scene.getStylesheets().add(HelloApplication.class.getResource("bootstrap3.css").toExternalForm());
            stage.setScene(scene);
            stage.initOwner(HelloApplication.APP);
            stage.initModality(Modality.APPLICATION_MODAL);
            stage.setTitle(title);
            stage.setHeight(y);stage.setWidth(x);

        }catch (IOException e){
            e.printStackTrace();
        }
        stage.show();
        return stage;
    }
    public static void changeView(String url,int x,int y){
        Parent root = null;
        try {
            root = FXMLLoader.load(HelloApplication.class.getResource(url));
            Scene scene = new Scene(root);
            scene.getStylesheets().add(HelloApplication.class.getResource("bootstrap3.css").toExternalForm());
            APP.setWidth(x);APP.setHeight(y);
            APP.setScene(scene);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    // 显示提示对话框
    public static void showAlert(String title, String message) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle(title);
        alert.setHeaderText(null);
        alert.setContentText(message);
        alert.showAndWait();
    }
    // 显示确认对话框
    public static Alert showConfirmAlert(String title,String message){
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle(title);
        alert.setHeaderText(null);
        alert.setContentText(message);
        alert.showAndWait();
        return alert;
    }

    public static Stage APP;
    @Override
    public void start(Stage stage) throws IOException {
        APP = stage;
        stage.setTitle("Java实验测试平台!");
        changeView("hello-view.fxml",640,450);
        stage.setResizable(false);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }

}